#include <stdio.h>

int Count_Digit ( const int N, const int D );

int main()
{
    int N, D;
	
    scanf("%d %d", &N, &D);
    printf("%d\n", Count_Digit(N, D));
    return 0;
}
int Count_Digit(const int N, const int D)
{
  int a=0,b,n=N;
  while(n!=0)
  {
    b=n%10;
    if(b==D)
    a++;
    n=n/10;
  }
  return a;
}